package com.client;

import com.domain.LoginForm;
import com.struct.Request;
import com.struct.RequestHeader;
import io.netty.channel.Channel;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by Greg.chen on 2016-03-20.
 */
public class SwingClient {


    public JPanel panel1;
    private JPanel logInPanel;
    private JButton button1;
    private JTextField textField1;
    private JPasswordField passwordField1;
    public JTextArea textArea1;

    public Channel channel;

    public SwingClient(){

        button1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                channel.writeAndFlush(buildLoginReq());
            }
        });
    }

    private Request<LoginForm> buildLoginReq() {
        Request<LoginForm> request = new Request<LoginForm>();

        RequestHeader header = new RequestHeader();
        header.setUri("/login");
        request.setHeader(header);

        LoginForm  form = new LoginForm(this.textField1.getText(), new String(this.passwordField1.getPassword()));
        request.setBody(form);

        return request;
    }

}
